package com.smarkparking.controller;

import com.smarkparking.pojo.Order;
import com.smarkparking.pojo.Parking;
import com.smarkparking.pojo.Superuser;
import com.smarkparking.pojo.Userproposal;
import com.smarkparking.service.OrderService;
import com.smarkparking.service.ParkingService;
import com.smarkparking.service.SuperuserService;
import com.smarkparking.service.UserproposalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 刘涛
 * @create 2021/11/17 21:22
 */
@RestController
@CrossOrigin
@RequestMapping("/superUser")
public class SuperuserController {
    @Autowired
    private SuperuserService superuserService;
    @Autowired
    private ParkingService parkingService;
    @Autowired
    private OrderService orderService;
    @Autowired
    private UserproposalService userproposalServicel;

    @RequestMapping("/findByName")
    public boolean findByName(@RequestParam("name") String name, @RequestParam("password") String password) {
        try {
            Superuser superuser = superuserService.selectSuUserByName(name);
            if (superuser.getPassword().equals(password)) {
                return true;
            }

        } catch (Exception e) {
            return false;
        }
        return false;
    }

    @RequestMapping("/deleteParking")
    public void deleteParking(@RequestParam("id") Integer id) {
        parkingService.deleteParking(id);
    }

    @RequestMapping("/updateParking")
    public boolean updateParking(@RequestParam("id") Integer id, @RequestParam("address") String address, @RequestParam("parkingSpaceNumber") String parkingSpaceNumber, @RequestParam("price") Double price, @RequestParam("state") Integer state) {
        boolean b = parkingService.updateParking(id, address, parkingSpaceNumber, price, state);
        return b;
    }

    @RequestMapping("/addParking")
    public boolean addParking(@RequestParam("address") String address, @RequestParam("parkingSpaceNumber") String parkingSpaceNumber, @RequestParam("price") Double price, @RequestParam("state") Integer state) {
        boolean b = parkingService.addParking(address, parkingSpaceNumber, price, state);
        return b;
    }

    @RequestMapping("/findAll")
    public List<Parking> findAll() {
        List<Parking> all = parkingService.findAll();
        return all;
    }

    @RequestMapping("/findAllOrder")
    public List<Order> findAllOrder() {
        List<Order> allOrder = orderService.findAllOrder();
        return allOrder;
    }

    @RequestMapping("/findCompleteOrder")
    public List<Order> findCompleteOrder() {
        List<Order> completeOrder = orderService.findCompleteOrder(null);
        return completeOrder;
    }

    @RequestMapping("/findNoCompleteOrder")
    public List<Order> findNoCompleteOrder() {
        List<Order> completeOrder = orderService.findNoCompleteOrder(null);
        return completeOrder;
    }

    @RequestMapping("/deleteOrder")
    public void deleteOrder(Long id) {
        orderService.deleteOrder(id);
    }

    @RequestMapping("/updateOrder")
    public boolean updateOrder(@RequestParam("id") Long id, @RequestParam("name") String name, @RequestParam("parkingSpaceNumber") String parkingSpaceNumber, @RequestParam("licensePlateNumber") String licensePlateNumber, @RequestParam("orderPrice") Double orderPrice, @RequestParam("orderState") Integer orderState) {
        return orderService.updateOrder(id, name, parkingSpaceNumber, licensePlateNumber, orderPrice, orderState);
    }

    @RequestMapping("/findProposalAll")
    public List<Userproposal> findProposalAll() {
        return userproposalServicel.findProposalAll();
    }

    @RequestMapping("/readProposal")
    public void readProposal(Integer id) {
        userproposalServicel.readProposal(id);
    }
}
